import  * as Type from './mutation-types'
import {
    setStore,
    removeStore
} from '../util/utils';

// 关于搜索历史
function SET_SEARCH_HISTORY_FUN(searchHistory, keyword) {
    let index = searchHistory.indexOf(keyword);
    if (searchHistory.indexOf(keyword) > -1) {
        searchHistory.splice(index, 1);
    }
    searchHistory.unshift(keyword);
    setStore(Type.SEARCH_HISTORY, searchHistory);
}

export const SET_SEARCH_HISTORY = SET_SEARCH_HISTORY_FUN;

function CLEAR_SEARCH_HISTORY_FUN(searchHistory) {
    searchHistory.splice(0);
    removeStore(Type.SEARCH_HISTORY);
}

export const CLEAR_SEARCH_HISTORY = CLEAR_SEARCH_HISTORY_FUN;


// 关于读书列表
function SET_BOOK_FUN(bookList) {
    setStore(Type.SHELF_BOOK, bookList);
}

export const SET_BOOK = SET_BOOK_FUN;

function SET_CUR_BOOK_FUN(book) {
    setStore(Type.CUR_BOOK, book);
}
export const SET_CUR_BOOK = SET_CUR_BOOK_FUN;


export const SET_NIGHT_MODE = (isNight) => {
    setStore(Type.NIGHT_MODE, isNight);
};

export const SET_SKIN_COLOR = (skinColor) => {
    setStore(Type.SKIN_COLOR, skinColor);
};

export const SET_FONT_SIZE = (fontSize) => {
    setStore(Type.FONT_SIZE, fontSize);
};

export const SET_HISTORY_BOOK = (book) => {
    setStore(Type.HISTORY_BOOK, book);
};